
class TestDemo1{
    public static int count=0;
    public synchronized void fun(){
        count++;
    }
    public  void fun1(){
        count++;
    }
    public static synchronized void fun2(){
        count++;
    }
}
public class Test {

    public static void main(String[] args) throws InterruptedException {
        TestDemo1 testDemo1=new TestDemo1();
        TestDemo1 testDemo2=new TestDemo1();
        Thread thread1 =new Thread(){
            @Override
            public void run() {
                for (int i = 0; i < 500; i++) {
                    testDemo1.fun();
                }
            }
        };
        Thread thread2=new Thread(()->{
            for (int i = 0; i < 500; i++) {
                testDemo1.fun1();
            }
        });

        thread1.start();
        thread2.start();

        thread1.join();
        thread2.join();
        System.out.println(testDemo1.count);


    }
}
